package android.support.v4.os;

import android.net.wifi.WifiInfo;

import com.edroid.autorunner.um.UserManager;

import de.robv.android.xposed.XposedHelpers;

public class EWifiInfo extends EHook {

	@Override
	public String getClassName() {
		return WifiInfo.class.getName();
	}
	
	private enum Method {
		getMacAddress,
		getBSSID,
		getSSID
	}

	@Override
	public void hook() {
		log.d("EWifiInfo hook>>>");
		
		for(Method method : Method.values()) {
			XposedHelpers.findAndHookMethod(getClassName(), null, 
					method.name(),
					this);
		}
	}

	@Override
	protected void after(String name, Object[] args, MethodHookParam param) {
		if(UserManager.currentUserInfo() == null)
			return;
		
		log.i("after " + name + " ret=" + param.getResult());
		
		if(Method.getMacAddress.name().equals(name)) {
			param.setResult(UserManager.currentUserInfo().mac);
		} else if(Method.getBSSID.name().equals(name)) {
			param.setResult(UserManager.currentUserInfo().BSSID);
		} else if(Method.getSSID.name().equals(name)) {
			param.setResult(UserManager.currentUserInfo().SSID);
		}
	}
}
